#include <mysql/mysql.h>
#include <iostream>
#include <string>

using namespace std;

const std::string host = "localhost";
const std::string db = "test_data";

int main(int argc, char* argv[])
{
     if (argc != 3)
    {
        std::cout << "./mysql user passwd" << std::endl;
        return -1;
    }

    MYSQL* sql = mysql_init(nullptr);
    if (sql == nullptr)
    {
        cout << "mysql init error" << endl;
        return -1;
    }

    if (mysql_real_connect(sql, host.c_str(), argv[1], argv[2], db.c_str(), 3306, nullptr, 0) == nullptr)
    {
        cout << "connect error" << endl;
        return -2;
    }
    cout << "connect success" << endl;

    mysql_set_character_set(sql, "utf8");

    mysql_query(sql, "insert into user (id, name, password, birthday) values(2, '李四', '12345', '2013-04-13')");

    return 0;
}